package cc.booku.owlbox.VideoPlayer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.concurrent.Executors;

import cc.booku.owlbox.R;
import cc.booku.owlbox.SearchPage.AsyncTaskImageLoad;

public class player_discuss_Adapter extends BaseAdapter implements ListAdapter {


    private ArrayList<player_discuss_class> player_discuss_classList;
    private int id;
    private Context context;
    private LayoutInflater inflater;

    public player_discuss_Adapter(int item, Context context, ArrayList<player_discuss_class> player_discuss_classList) {
        this.player_discuss_classList = player_discuss_classList;
        this.context = context;
        this.id = item;
        inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return player_discuss_classList.size();
    }

    @Override
    public Object getItem(int i) {
        return player_discuss_classList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("WrongConstant")
    @Override

    public View getView(int i, View view, ViewGroup viewGroup) {

//    `comment_id`      主键id
//     ,`comment_rid`   视频id
//     ,`user_id`       用户id
//     ,`comment_name`   用户名
//     ,`comment_content`  评论内容
//     ,`comment_time`      评论事件

        TextView comment_name = null;
        TextView comment_content = null;
        TextView comment_time = null;
        TextView comment_value = null;

        player_discuss_Adapter.ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(id, null);

            comment_name = (TextView) view.findViewById(R.id.player_discuss_comment_nameid);
            comment_time = (TextView) view.findViewById(R.id.player_discuss_comment_timeid);
            comment_content = (TextView) view.findViewById(R.id.player_discuss_comment_contentid);
            comment_value = (TextView) view.findViewById(R.id.player_discuss_comment_valueid);


            view.setTag(new ViewHolder(comment_name, comment_time, comment_content, comment_value));
        } else {
            player_discuss_Adapter.ViewHolder viewHolder1 = (player_discuss_Adapter.ViewHolder) view.getTag(); // 重新获取ViewHolder
            comment_name = viewHolder1.comment_name;
            comment_time = viewHolder1.comment_time;
            comment_content = viewHolder1.comment_content;
            comment_value = viewHolder1.comment_value;


        }
        player_discuss_class player_discuss_classListc = (player_discuss_class) player_discuss_classList.get(i); // 获取当前项的实例

        //video_public_classListc
        comment_name.setText(player_discuss_classListc.getComment_name().toString());//对象为空
        comment_time.setText(player_discuss_classListc.getComment_time().toString());
        comment_content.setText(player_discuss_classListc.getComment_content().toString());
        comment_value.setText(player_discuss_classListc.getComment_value().toString());

        return view;

    }


    private final class ViewHolder {
        TextView comment_name = null;
        TextView comment_content = null;
        TextView comment_time = null;
        TextView comment_value = null;


        public ViewHolder(TextView comment_time, TextView comment_name, TextView comment_content, TextView comment_value) {
            this.comment_content = comment_content;
            this.comment_time = comment_time;
            this.comment_name = comment_name;
            this.comment_value = comment_value;

        }

    }
}